package com.huaguoguo.huaguoguo.filter;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * 类说明： <br/>
 * author:huaguoguo
 * Date: 2019/2/26
 * Time: 23:31
 */
@Configuration
public class GlobalRouteFilter implements GlobalFilter {
    private Logger logger = LoggerFactory.getLogger(GlobalRouteFilter.class);
    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        logger.info("请求进来啦:"+exchange.getRequest().getURI());

        ServerHttpRequest.Builder builder = exchange.getRequest().mutate();
        builder.header("GlobalFilter","GlobalFilter success");
        chain.filter(exchange.mutate().request(builder.build()).build());
        return chain.filter(exchange.mutate().request(builder.build()).build());
    }
}
